package com.lft08.priority;

/**
 * Function: 		A {@code TestPriority} object With Some FUNCTION.<br/>
 * Reason:   		ADD REASON.<br/>
 * Date:            2021-01-27 19:15<br/>
 * <p>
 * Class Name:      TestPriority<br/>
 * Package Name:    com.lft08.priority<br/>
 * @author Laifengting / E-mail:laifengting@foxmail.com
 * @version 1.0.0
 * @since JDK 8
 */
public class TestPriority {
	public static void main(String[] args) {
		// 主线各默认优先级
		System.out.println(Thread.currentThread().getName() + " ---> " + Thread.currentThread().getPriority());
		
		MyPriority myPriority = new MyPriority();
		Thread thread1 = new Thread(myPriority, "线程1");
		Thread thread2 = new Thread(myPriority, "线程2");
		Thread thread3 = new Thread(myPriority, "线程3");
		Thread thread4 = new Thread(myPriority, "线程4");
		Thread thread5 = new Thread(myPriority, "线程5");
		Thread thread6 = new Thread(myPriority, "线程6");
		
		// 设置线程优先级
		thread1.setPriority(Thread.MIN_PRIORITY);
		thread1.start();
		thread2.setPriority(3);
		thread2.start();
		thread3.setPriority(Thread.NORM_PRIORITY);
		thread3.start();
		thread4.setPriority(7);
		thread4.start();
		thread5.setPriority(9);
		thread5.start();
		thread6.setPriority(Thread.MAX_PRIORITY);
		thread6.start();
		
	}
}

class MyPriority implements Runnable {
	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + " ---> " + Thread.currentThread().getPriority());
	}
}